package aop_ex;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.util.StopWatch;

public class AroundSample implements MethodInterceptor {

    public Object invoke(MethodInvocation invocation) throws Throwable {
        
        String methodName = invocation.getMethod().getName();
        StopWatch sw = new StopWatch();
        
        sw.start(methodName);
        
        System.out.println("pointcut: " + methodName + " is calling.");
        System.out.println("Create Connection..");
        Object rtnObj = invocation.proceed();
        
        sw.stop();
        System.out.println();
        System.out.println("제1조 실행결과: " + methodName + " is called.");
        System.out.println(" 처리시간 " + sw.getTotalTimeMillis() / 1000 + "초");
        System.out.println("db closed..");
        
        return rtnObj;
    }
}